package com.shd.edanpei.util;

import com.google.gson.Gson;
import com.shd.edanpei.bean.NeedBean;

import java.lang.reflect.Type;
import java.util.HashMap;
import java.util.List;

@SuppressWarnings("ALL")
public abstract class GsonUtil {

    public static Gson getGson() {
        return GsonHolder.GSON;
    }

    private static final class GsonHolder {
        private static final Gson GSON = new Gson();
    }


    public static String listToJson(List list) {
        return getGson().toJson(list);
    }

    public static String toJson(Object object) {
        return getGson().toJson(object);
    }

    public static Object toObjcet(String json) {
        return getGson().toJson(json);
    }


    public static HashMap<String, Object> toMap(Object object) {
        return getGson().fromJson(getGson().toJson(object), HashMap.class);
    }

    public static List<NeedBean> toList(String data, Type type) {

        return getGson().fromJson(data, type);
    }



}
